//package com.scriptlib;
//
//import java.io.IOException;
//import java.net.Inet4Address;
//import java.net.InetSocketAddress;
//import java.net.NetworkInterface;
//import java.net.ServerSocket;
//import java.net.InetAddress;
//import java.net.SocketException;
//import java.util.Enumeration;
//
//public class ScreenShotHelper {
//
//    private ServerSocket serverSocket;
//    private Thread thread;
//    private int localPort;
//    private String localAddress;
//
//    public ScreenShotHelper() throws IOException {
//        serverSocket = new ServerSocket();
//        localAddress = _GetLocalAddress();
//        serverSocket.bind(new InetSocketAddress(localAddress, 0));
//        localPort = serverSocket.getLocalPort();
//    }
//
//    public int GetLocalPort() {
//        return localPort;
//    }
//
//    public String GetLocalAddress() {
//        return localAddress;
//    }
//
//    public void Start(Object obj) throws IOException {
//        thread = new ScreenShotThread(serverSocket, obj );
//        thread.start();
//    }
//
//    public void Close() throws IOException {
//        if (thread != null) {
//            thread.interrupt();
//        }
//        serverSocket.close();
//    }
//
//    private String _GetLocalAddress() throws SocketException {
//        for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); ((Enumeration) en).hasMoreElements(); ) {
//            NetworkInterface intf = en.nextElement();
//            for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses();
//                 enumIpAddr.hasMoreElements(); ) {
//                InetAddress inetAddress = enumIpAddr.nextElement();
//                if (!inetAddress.isLoopbackAddress() && (inetAddress instanceof Inet4Address)) {
//                    return inetAddress.getHostAddress();
//                }
//            }
//        }
//        return "null";
//    }
//}
